package com.xms.schema.service.stringmap;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xms.datacore.service.DeleterService;
import com.xms.schema.entity.StringMap;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;
import java.util.Collection;
import java.util.UUID;

/**
 * <p>
 * StringMapDeleterService
 * </p>
 *
 * @author migo
 * @since 2021/9/8
 */
@CacheConfig(cacheNames = "schema.stringmap", keyGenerator = "CacheKeyGenerator")
@Service
public class StringMapDeleterService extends DeleterService<StringMap> implements IStringMapDeleterService {

    @CacheEvict(allEntries = true, condition = "#result == true")
    @Transactional(rollbackFor=Exception.class)
    @Override
    public boolean deleteById(UUID id) throws SQLException {
        return super.removeById(id);
    }

    @CacheEvict(allEntries = true, condition = "#result == true")
    @Transactional(rollbackFor=Exception.class)
    @Override
    public boolean deleteMany(Wrapper<StringMap> queryWrapper) throws SQLException {
        return super.remove(queryWrapper);
    }

    @CacheEvict(allEntries = true, condition = "#result == true")
    @Transactional(rollbackFor=Exception.class)
    @Override
    public boolean deleteByIds(Collection<UUID> idList) throws SQLException {
        return super.removeByIds(idList);
    }

    @CacheEvict(allEntries = true, condition = "#result == true")
    @Transactional(rollbackFor=Exception.class)
    @Override
    public boolean deleteByAttributeId(UUID id) {
        return super.remove(new LambdaQueryWrapper<StringMap>().eq(StringMap::getAttributeid, id));
    }
}
